import sympy
from tqdm import tqdm


def fix_pos_sum(number, pos):
    t = 0
    for i in range(6):
        if i not in pos:
            t += number // pow(10, i) % 10
    return t


def replace_number(number, pos):
    t = 0
    res = []
    s = str(number)
    num_arr = list(s)
    flag = 1 if 0 in pos else 0
    for i in range(flag, 10):
        for j in pos:
            num_arr[j] = str(i)
        s = ''.join(num_arr)
        if sympy.isprime(int(s)):
            res.append(int(s))
            t += 1
    if t >= 8:
        print(res)
        return number, pos
    else:
        return None


replace_index = [[0, 1, 2], [0, 2, 4], [2, 3, 4], [1, 3, 4], [1, 2, 4], [1, 2, 3], [0, 2, 3], [0, 1, 3], [0, 3, 4],
                 [0, 1, 4]]
for index in tqdm(replace_index):
    for num in range(100000, 1000000):
        if fix_pos_sum(num, index) % 3 == 0:
            continue
        if replace_number(num, index) is not None:
            if sympy.isprime(num):
                print(num, index)
            break  # find the smallest
